<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>封装ajax</title>
</head>

<body>
    <button id="btn">点击发送请求</button>
</body>

</html>
<script src="./promise封装.js"></script>
<script>

    const getCar = () => ajax({
        url: "http://chst.vip:8081/data/index.json"
    })
    const getWeather = () => ajax({
        url: "http://chst.vip/weather/getWeather"
    })

    btn.onclick = function () {
        console.log(111);
        //传统回调
        /*   ajax({
              url: "http://www.chst.vip/weather/getWeather"
          })
              .then(res => {
                  console.log(res);
              }) */

        //promise
        getWeather()
            .then(res => {
                console.log(res);
                return getCar()
            })

            .then(param => {
                console.log(param);
            })
    }
</script>